package cs5226.dao;

import java.sql.SQLException;
import java.util.List;

import cs5226.model.PercentageSingleValueStatistics;

public class MemorySortDAO extends AWRStatisticsDAO {
	public static List<PercentageSingleValueStatistics> getMemorySortRatio()
			throws SQLException {
		String exprStat = "(100* sum(decode(a.stat_name,'sorts (memory)', a.value)) / " +
				" (sum(decode(a.stat_name,'sorts (memory)', a.value))+ " +
				" sum(decode(a.stat_name,'sorts (disk)', a.value))))";
		String awrTable = "DBA_HIST_SYSSTAT";
		String filter = "a.stat_name in ('sorts (memory)', 'sorts (disk)')";
		
		return searchAWRStatistics(PercentageSingleValueStatistics.class, exprStat, awrTable, DAYSLATEST, filter);
	}

	public static List<PercentageSingleValueStatistics> getMemorySortRatio(String fromDate, String toDate)
			throws SQLException {
		String exprStat = "(100* sum(decode(a.stat_name,'sorts (memory)', a.value)) / " +
				" (sum(decode(a.stat_name,'sorts (memory)', a.value))+ " +
				" sum(decode(a.stat_name,'sorts (disk)', a.value))))";
		String awrTable = "DBA_HIST_SYSSTAT";
		String filter = "a.stat_name in ('sorts (memory)', 'sorts (disk)')";
		
		return searchAWRStatisticsWithinAPeriod(fromDate, toDate, PercentageSingleValueStatistics.class, exprStat, awrTable, DAYSLATEST, filter);
	}
	
	public static List<PercentageSingleValueStatistics> getMemorySortRatioLatest()
			throws SQLException {
		String exprStat = "(100* sum(decode(a.stat_name,'sorts (memory)', a.value)) / " +
				" (sum(decode(a.stat_name,'sorts (memory)', a.value))+ " +
				" sum(decode(a.stat_name,'sorts (disk)', a.value))))";
		String awrTable = "DBA_HIST_SYSSTAT";
		String filter = "a.stat_name in ('sorts (memory)', 'sorts (disk)')";
		
		return searchAWRStatisticsLatest(PercentageSingleValueStatistics.class, exprStat, awrTable, DAYSLATEST, filter);
	}
}
